package com.sat.rest.papeletas.controller;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sat.rest.papeletas.domain.PapeletaList;
import com.sat.rest.papeletas.service.PapeletaService;

@Controller
public class PapeletaController {
	protected static Logger logger = Logger.getLogger("controller");

	@Resource(name = "papeletaService")
	private PapeletaService papeletaService;

	@RequestMapping(value = "/papeletas", method = RequestMethod.GET, headers = "Accept=application/xml, application/json")
	public @ResponseBody
	PapeletaList getPerson() {
		logger.debug("Provider has received request to get all papeletas");

		// Call service here
		PapeletaList result = new PapeletaList();

		result.setData(papeletaService.getAll());

		return result;
	}

	@RequestMapping(value = "/papeletas/{dni}", method = RequestMethod.GET, headers = "Accept=application/html, application/xhtml+xml")
	public String getPapeletasPorDniHtml(@PathVariable("dni") String dni,
			Model model) {
		logger.debug("Provider has received request to get all papeletas");

		// Call service here

		model.addAttribute("papeletas", papeletaService.obtenerSanciones(dni));

		// This will resolve to /WEB-INF/jsp/getpage.jsp
		return "getpage";
	}
}
